package com.example.juc.pool;


import java.util.concurrent.*;

public class Demo {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();//单一
        Executors.newFixedThreadPool(5);// 固定数量
        Executors.newCachedThreadPool(); //可伸缩的
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy());


        for (int i= 0 ;i<10;i++){
            executorService.execute(()->{
                System.out.println(Thread.currentThread().getName()+"-> ok");
            });
        }
        executorService.shutdown();
    }
}
